import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
// import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters
import drag from './directive/el-drag-dialog/drag'

import {
  deepClone,
  delConfirm,
  getType
} from '@/utils'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const {
    mockXHR
  } = require('../mock')
  mockXHR()
}
Vue.prototype.$deepClone = deepClone //
Vue.prototype.$delConfirm = delConfirm //
Vue.prototype.$getType = getType //

Vue.directive('el-drag-dialog', drag)

//全局设置点击遮罩层不关闭 Dialog
Element.Dialog.props.closeOnClickModal.default = false;
Vue.config.productionTip = false;
//全局设置点击遮罩层不关闭 Dialog

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  // locale: enLang // 如果使用中文，无需设置，请删除
})

Vue.mixin({
  methods: {
    hasBtn(btnCode) {
      let list = store.state.user.userBtns
      return list.includes(btnCode)
    },
    getBit(value, bit) {
      let str = Number(value);
      str = str.toFixed(bit)
      console.log(str)
      return str;
    },
    proving2(e, type) {
      // console.log(e.target.value)
      // console.log(this.getBit(e.target.value, 1))
      var keynum = window.event ? e.keyCode : e.which; //获取键盘码
      var keychar = String.fromCharCode(keynum); //获取键盘码对应的字符
      if (keynum == 189 || keynum == 109) { //禁止输入负数
        this.$message.warning('禁止输入负数')
        e.target.value = 0
      }
      // if (e.target.value.indexOf('.') == 1) { //如果值里面有’.‘的话，进去检测位小数点大于1位的话只保留一位
      //   var x = String(e.target.value).indexOf(".") + 1; //得到小数点的位置
      //   var y = String(e.target.value).length - x; //小数点的位数
      //   if (y > 1) {
      //     e.target.value = this.getBit(e.target.value, 1)
      //   }
      // }
      if (type == "%" && e.target.value > 100) { //大于100分时候设置100分
        this.$message.warning('最高值为100%')
        e.target.value = 100
      }
      // if (e.target.value == 100) { //当100分时候去掉小数点
      //   if (keynum == 189 || keynum == 190 || keynum == 109) {
      //     e.target.value = 100
      //   }
      // }

    }
  }
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
